package com.smartStatus.task.config;

import com.smartStatus.task.properties.SmsProperties;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @ClassName : TaskAutoConfiguration
 * @Author : lby
 * @Date: 2020/11/19 9:40
 * @Description : 任务调度配置类
 */
@AllArgsConstructor
@Slf4j
@EnableConfigurationProperties({SmsProperties.class})
public class TaskAutoConfiguration {
    private final SmsProperties smsProperties;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(smsProperties.getAdminAddresses());
        xxlJobSpringExecutor.setAppName(smsProperties.getExecutorAppName());
        xxlJobSpringExecutor.setIp(smsProperties.getExecutorIp());
        xxlJobSpringExecutor.setPort(smsProperties.getExecutorPort());
        xxlJobSpringExecutor.setAccessToken(smsProperties.getAccessToken());
        xxlJobSpringExecutor.setLogPath(smsProperties.getExecutorLogPath());
        xxlJobSpringExecutor.setLogRetentionDays(smsProperties.getExecutorLogRetentionDays());
        return xxlJobSpringExecutor;
    }
}
